//
//  GRLoginAction.m
//  YC_GRice
//
//  Created by LiuFeng on 2018/7/12.
//  Copyright © 2018年 YeCai. All rights reserved.
//

#import "GRLoginAction.h"
#import "UIButton+Common.h"

@implementation GRLoginAction

+ (void)getVerificationCode:(NSDictionary *)option {
    NSDictionary *paramer = option[@"paramer"];
    UIButton *sender      = option[@"sender"];
    
    NSString *url = [NSString stringWithFormat:@"%@captcha",GRDeliveryAPI];
    
    [RequestManager TouristsRequestWithURLString:url Method:GR_POST Paramers:paramer completionHandler:^(BOOL success, id responseObject, GRError *error) {
        if (success) {
            [sender openTimer:60 Title:@"获取验证码"];
        }else {
            NSLog(@"%@",error);
        }
    }];
}


+ (void)gotoLoginWithParamer:(NSDictionary *)paramer completionHandler:(RequestBlock)completionHandler {
    NSString *url = [NSString stringWithFormat:@"%@gmUser/login",GRDeliveryAPI];
    
    [RequestManager TouristsRequestWithURLString:url Method:GR_POST Paramers:paramer completionHandler:^(BOOL success, id responseObject, GRError *error) {
        completionHandler(success, responseObject, error);
    }];
}

+ (void)associatedMobile:(NSDictionary *)paramer completionHandler:(RequestBlock)completionHandler {
    NSString *url = [NSString stringWithFormat:@"%@gmUser/bindMobile",GRDeliveryAPI];

    [RequestManager TouristsRequestWithURLString:url Method:GR_POST Paramers:paramer completionHandler:^(BOOL success, id responseObject, GRError *error) {
        completionHandler(success, responseObject, error);
    }];
}


+ (void)setPasswordWithRegisterMode:(NSInteger)registerMode paaramers:(NSDictionary *)paramers completionHandler:(RequestBlock)completionHandler {
    NSString *path = @"";
    NSString *tip  = @"设置密码成功";
    switch (registerMode) {
        case 1:{
            path = @"gmUser/register";
            tip  = @"注册成功";
        }
            break;
        
        case 2:{
            path = @"gmUser/password/create";
        }
            break;

        case 4:{
            path = @"gmUser/password/forget";
        }
            break;

        case 5:{
            path = @"profiles/auth/safePassword";
        }
            break;
            
        case 7:{
            path = @"profiles/auth/safePassword";
        }
            break;

        default:
            break;
    }
    
    NSString *url = [NSString stringWithFormat:@"%@%@",GRDeliveryAPI, path];
    
    [RequestManager MembershipRequestWithURLString:url Method:GR_POST Paramers:paramers completionHandler:^(BOOL success, id responseObject, GRError *error) {
        NSDictionary *response = @{@"tip"            : tip,
                                   @"responseObject" : responseObject ? responseObject : @{}
                                   };
        completionHandler(success, response, error);
    }];
}


+ (void)modifyPasswordWithRegisterMode:(NSInteger)registerMode paramers:(NSDictionary *)paramers completionHandler:(RequestBlock)completionHandler {
    NSString *path = (registerMode == 3 ? @"gmUser/password/update" : @"profiles/auth/safePassword");
    NSString *url = [NSString stringWithFormat:@"%@%@",GRDeliveryAPI, path];

    [RequestManager MembershipRequestWithURLString:url Method:GR_PUT Paramers:paramers completionHandler:^(BOOL success, id responseObject, GRError *error) {
        completionHandler(success, responseObject, error);
    }];
}




@end
